<%@ page import="books4africa.Fulfillment" %>
<!doctype html>
<html>
	<head>
		<meta name="layout" content="main">
		<g:set var="entityName" value="${message(code: 'fulfillment.label', default: 'Fulfillment')}" />
		<title><g:message code="default.create.label" args="[entityName]" /></title>
	</head>
	<body>
		<a href="#create-fulfillment" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>
		<div class="nav" role="navigation">
			<ul>
				<li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
				<li><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></li>
			</ul>
		</div>
		
		<div id="show-bookRequest" class="content scaffold-show" role="main">
			<h1>Book Request Information</h1>
			<g:if test="${flash.message}">
			<div class="message" role="status">${flash.message}</div>
			</g:if>
			<ol class="property-list bookRequest">
			
				<g:if test="${bookRequestInstance?.user}">
				<li class="fieldcontain">
					<span id="user-label" class="property-label"><g:message code="bookRequest.user.label" default="Teacher" /></span>
					
						<span class="property-value" aria-labelledby="user-label">${bookRequestInstance?.user?.encodeAsHTML()}</span>
					
				</li>
				</g:if>
				
			    <g:if test="${bookRequestInstance?.book}">
				<li class="fieldcontain">
					<span id="book-label" class="property-label"><g:message code="bookRequest.book.label" default="Book" /></span>
					
						<span class="property-value" aria-labelledby="book-label">${bookRequestInstance?.book?.encodeAsHTML()}</span>
					
				</li>
				</g:if>
			
				<g:if test="${bookRequestInstance?.description}">
				<li class="fieldcontain">
					<span id="description-label" class="property-label"><g:message code="bookRequest.description.label" default="Description" /></span>
					
						<span class="property-value" aria-labelledby="description-label"><g:fieldValue bean="${bookRequestInstance}" field="description"/></span>
					
				</li>
				</g:if>
				
				<g:if test="${bookRequestInstance?.bookQty}">
				<li class="fieldcontain">
					<span id="description-label" class="property-label"><g:message code="bookRequest.bookQty.label" default="Requested Qty" /></span>
					
						<span class="property-value" aria-labelledby="description-label"><g:fieldValue bean="${bookRequestInstance}" field="bookQty"/></span>
					
				</li>
				</g:if>
			
				<g:if test="${bookRequestInstance?.dateRequested}">
				<li class="fieldcontain">
					<span id="dateRequested-label" class="property-label"><g:message code="bookRequest.dateRequested.label" default="Date Requested" /></span>
					
						<span class="property-value" aria-labelledby="dateRequested-label"><g:formatDate date="${bookRequestInstance?.dateRequested}" type="date" style="MEDIUM" /></span>
					
				</li>
				</g:if>		
			</ol>
			</div>

	    
		<div id="create-fulfillment" class="content scaffold-create" role="main">
			<h1>Available Book Donations</h1>
			<g:if test="${flash.message}">
			<div class="message" role="status">${flash.message}</div>
			</g:if>
			<table>
				<thead>
					<tr>
					
						<g:sortableColumn property="donationDate" title="${message(code: 'donation.donationDate.label', default: 'Donation Date')}" />
					
						<th><g:message code="donation.book.label" default="Book" /></th>
					
						<g:sortableColumn property="bookQty" title="${message(code: 'donation.bookQty.label', default: 'Qty On-Hand')}" />
						<th>Filled Qty</th>
						<th><g:message code="donation.donor.label" default="Donor" /></th>
						<th></th>
					
					</tr>
				</thead>
				<tbody>
				<g:each in="${donationInstanceList}" status="i" var="donationInstance">
				<g:form action="save" >
					<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
						
						<td><g:link action="show" id="${donationInstance.donation.id}"><g:hiddenField name="id" value="${donationInstance.donation.id }"/><g:hiddenField name="bookRequestId" value="${bookRequestInstance.id }"/>
						<g:formatDate date="${donationInstance.donation.donationDate}" type="date" style="MEDIUM"/>
						</g:link></td>
					
						<td>${fieldValue(bean: donationInstance, field: "book")}</td>
					
						<td>${fieldValue(bean: donationInstance, field: "qty")}</td>
						
						<td><g:field type="number" min="0" max="${fieldValue(bean: donationInstance.donation, field: 'bookQty')}" name="qtyFilled" value="${fieldValue(bean: donationInstance.donation, field: 'bookQtyFilled')}"/></td>
					
						<td>${fieldValue(bean: donationInstance.donation, field: "donor")}</td>
						
						<td><g:submitButton name="create_${donationInstance.donation.id }" class="create" value="Add to Fulfillment" /></td>	
					</tr>
					</g:form>
				</g:each>
				</tbody>
			</table>
		</div>
	</body>
</html>
